package com.sto.stoapp.activity.administrator.hardware;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.text.InputType;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.EditText;

import com.sto.stoapp.activity.R;
import com.sto.stoapp.broadcast.HomeBroadAction;
import com.sto.stoapp.manager.SoundManager;
import com.sto.stoapp.util.Helper;
import com.sto.stoapp.widget.StoListenerActivity;

import sto.android.app.StoPdaKeyEvent;

/**
 * 采集数据
 * 
 * @author mgf
 * 
 */
@SuppressLint("HandlerLeak")
public class AdminCollectDataActivity extends StoListenerActivity{

	private EditText codeNumberEdit;



	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.admin_collect_data);
		this.setTitleBottom(R.string.collection_data,
				HomeBroadAction.ADMINISTRATOR_BROAD);
		initWidget();
	}

	private void initWidget() {
		codeNumberEdit = (EditText) findViewById(R.id.code_number_edit);
		codeNumberEdit.setInputType(InputType.TYPE_NULL);
		codeNumberEdit.setOnKeyListener(new OnKeyListener() {

			@Override
			public boolean onKey(View arg0, int arg1, KeyEvent arg2) {
				if (arg1 == StoPdaKeyEvent.KEYCODE_BUTTON_L1
						|| arg1 == StoPdaKeyEvent.KEYCODE_BUTTON_R1
						|| arg1 == StoPdaKeyEvent.KEYCODE_SCAN) {
					if (!scanStatus()) {
						startScan();
					}
				}
				return false;
			}
		});
	}


	
	// 添加小退功能
    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        if (keyCode == StoPdaKeyEvent.KEYCODE_DEL) {
            if (scanStatus()) {
                endScan();
            }
            this.finish();
        }
        return super.onKeyUp(keyCode, event);
    }

    @Override
    protected void onDestroy() {
  
    	super.onDestroy();
    }



	@Override
	protected void handlerScanData(String scanData) {
		Helper.showSoundAndVibrator(AdminCollectDataActivity.this, true);
		codeNumberEdit.setText(scanData);
		codeNumberEdit.setSelection(scanData.length());
		SoundManager.getInstance(AdminCollectDataActivity.this)
		.playSuccessSound();
		
	}
}
